﻿using System;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 一个内存队列缓存的类，数据类型为Int64
	/// </summary>
	// Token: 0x02000190 RID: 400
	public sealed class SoftCacheArrayLong : SoftCacheArrayBase
	{
		/// <summary>
		/// 实例化一个数据对象
		/// </summary>
		/// <param name="capacity"></param>
		/// <param name="defaultValue"></param>
		// Token: 0x060020B1 RID: 8369 RVA: 0x0009F324 File Offset: 0x0009D524
		public SoftCacheArrayLong(int capacity, int defaultValue)
		{
			bool flag = capacity < 10;
			if (flag)
			{
				capacity = 10;
			}
			base.ArrayLength = capacity;
			this.DataArray = new long[capacity];
			this.DataBytes = new byte[capacity * 8];
			bool flag2 = defaultValue != 0;
			if (flag2)
			{
				for (int i = 0; i < capacity; i++)
				{
					this.DataArray[i] = (long)defaultValue;
				}
			}
		}

		/// <summary>
		/// 用于从保存的数据对象初始化的
		/// </summary>
		/// <param name="dataSave"></param>
		/// <exception cref="T:System.NullReferenceException"></exception>
		// Token: 0x060020B2 RID: 8370 RVA: 0x0009F398 File Offset: 0x0009D598
		public override void LoadFromBytes(byte[] dataSave)
		{
			int num = dataSave.Length / 8;
			base.ArrayLength = num;
			this.DataArray = new long[num];
			this.DataBytes = new byte[num * 8];
			for (int i = 0; i < num; i++)
			{
				this.DataArray[i] = BitConverter.ToInt64(dataSave, i * 8);
			}
		}

		/// <summary>
		/// 线程安全的添加数据
		/// </summary>
		/// <param name="value">值</param>
		// Token: 0x060020B3 RID: 8371 RVA: 0x0009F3F4 File Offset: 0x0009D5F4
		public void AddValue(long value)
		{
			this.HybirdLock.Enter();
			for (int i = 0; i < base.ArrayLength - 1; i++)
			{
				this.DataArray[i] = this.DataArray[i + 1];
			}
			this.DataArray[base.ArrayLength - 1] = value;
			for (int j = 0; j < base.ArrayLength; j++)
			{
				BitConverter.GetBytes(this.DataArray[j]).CopyTo(this.DataBytes, 8 * j);
			}
			this.HybirdLock.Leave();
		}

		/// <summary>
		/// 数据的本身面貌
		/// </summary>
		// Token: 0x040007BB RID: 1979
		private long[] DataArray = null;
	}
}
